package com.lanyun.aicorrectassistant.controller.admin.assignmentTemplates;

import com.lanyun.aicorrectassistant.basic.bean.PageResult;
import com.lanyun.aicorrectassistant.basic.bean.Result;
import com.lanyun.aicorrectassistant.controller.admin.assignmentTemplates.vo.AssignmentTemplatesRequestPageVO;
import com.lanyun.aicorrectassistant.controller.admin.assignmentTemplates.vo.AssignmentTemplatesRequestVO;
import com.lanyun.aicorrectassistant.controller.admin.assignmentTemplates.vo.AssignmentTemplatesResponseVO;
import com.lanyun.aicorrectassistant.domain.assignmentTemplates.AssignmentTemplatesDomainService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import reactor.core.publisher.Flux;


/**
 * 作业模板表控制器
 *
 * @author makejava
 * @version 1.0
 * @date 2025-05-12 01:52:15
 */
@RequestMapping("/api-admin/assignmentTemplates")
@RestController("adminAssignmentTemplatesController")
@Slf4j
public class AssignmentTemplatesController {

    @Resource
    private AssignmentTemplatesDomainService assignmentTemplatesDomainService;

//    /**
//     * 生成AI思考过程
//     *
//     * @param assignmentTemplatesRequestVO
//     * @return
//     */
//    @PostMapping(value = "/generate-ai-thinking", produces = "text/event-stream;charset=UTF-8")
//    public Flux<String> generateAIThinkingProcess(@RequestBody(required = false) AssignmentTemplatesRequestVO assignmentTemplatesRequestVO) {
//        try {
//            return assignmentTemplatesDomainService.generateAIThinkingProcess(assignmentTemplatesRequestVO);
//        } catch (Exception e) {
//            log.error("生成AI思考过程失败", e);
//            return Flux.just("生成AI思考过程失败");
//        }
//    }

    @PostMapping(value = "/generate-ai-thinking")
    public Result<String> generateAIThinkingProcess(@RequestBody(required = false) AssignmentTemplatesRequestVO assignmentTemplatesRequestVO) {
        try {
            String result = assignmentTemplatesDomainService.generateAIThinkingProcess(assignmentTemplatesRequestVO);
            return Result.success(result);
        } catch (Exception e) {
            log.error("生成AI思考过程失败", e);
            return Result.fail(e.getMessage());
        }
    }



    /**
     * 分页查询作业模板表
     */
    @PostMapping("/page")
    public Result<PageResult<AssignmentTemplatesResponseVO>> page(@RequestBody AssignmentTemplatesRequestPageVO requestPageVO) {
        return Result.success(assignmentTemplatesDomainService.page(requestPageVO));
    }

    /**
     * 新增作业模板表
     */
    @PostMapping("/create")
    public Result<Boolean> create(@RequestBody AssignmentTemplatesRequestVO requestVO) {
        return Result.success(assignmentTemplatesDomainService.insert(requestVO));
    }

    /**
     * 修改作业模板表
     */
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody AssignmentTemplatesRequestVO requestVO) {
        return Result.success(assignmentTemplatesDomainService.update(requestVO));
    }

    /**
     * 删除作业模板表
     */
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.success(assignmentTemplatesDomainService.delete(id));
    }

    /**
     * 获取作业模板表详情
     */
    @GetMapping("/get/{id}")
    public Result<AssignmentTemplatesResponseVO> get(@PathVariable("id") Long id) {
        return Result.success(assignmentTemplatesDomainService.get(id));
    }
}
